package Exam.controller;

import Exam.model.LoginModel;
import Exam.pojo.User;
import Exam.util.JDBCUtil;


public class LoginController {
    private LoginModel loginModel = new LoginModel();

    public User login(String username, String password) {

        try {
            JDBCUtil.begin();

            if (username == null || password == null) {
                return null;
            }

            if (!loginModel.canLogin(username, password)) {
                return null;
            }
            User user = loginModel.login(username, password);

            return user;

        } finally {

            JDBCUtil.closeConn();
        }
    }
}
